package com.twu.biblioteca;

import java.io.PrintStream;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: anubhav
 * Date: 1/7/14
 * Time: 8:32 PM
 * To change this template use File | Settings | File Templates.
 */
public class MovieIssuer implements Action{ 
    
    private Map<String, LibraryItem> availableMovies;
    private Map<String, IssuedMovie> issuedMovies;
    private PrintStream out;
    private InputSeeker in;
    private String customerNumber;

    public MovieIssuer(Map<String, LibraryItem> avlist, Map<String, IssuedMovie> issuelist, PrintStream out,
                      InputSeeker in, String libNumber) {
        availableMovies = avlist;
        issuedMovies = issuelist;
        this.out = out;
        this.in = in;
        this.customerNumber = libNumber;
    }

    @Override
    public void executeAction() {
        AvailibilityChecker checker = new AvailibilityChecker(availableMovies);
        out.println("Please enter Movie name:");
        String MovieName = in.takeStringInput();
        if (checker.checkForItem(MovieName)) {
            issue(MovieName);
            out.println("Thank you! Enjoy the Movie");
        } else
            out.println("That Movie is not available.");
    }


    private void issue(String MovieName) {

        issuedMovies.put(MovieName, new IssuedMovie((Movie)availableMovies.get(MovieName), customerNumber));
        availableMovies.remove(MovieName);

    }
}

